
// ==============
$(function() {
	//alert($(".radio-input").length);
	var aLi = $(".radio-input");
	var showLi = $("#input-div li");
	for (var i = 0; i < aLi.length; i++) {
		aLi[i].index = i;
		aLi[i].onclick = function() {
			for (var i = 0; i < aLi.length; i++) {
				// aLi[i].className = "";
			}
			// this.className = "activ";

			for (var i = 0; i < showLi.length; i++) {
				showLi[i].className = "hide";
			}
			showLi[this.index].className = "show";
		}
	}
})

function funcc(yearDay, monthDay) {
	var dayQu;// 选中的月的天数
	var lefttime = $("#start").val(); // 获取到选取的时间  此例子的时间插件为年月的选择 获取到的格式为
	// 2018-03
	if (monthDay == '01' || monthDay == '03' || monthDay == '05'
			|| monthDay == '07' || monthDay == '08' || monthDay == 10
			|| monthDay == 12) {
		dayQu = 31;
		console.log("选中的是" + monthDay + "月的天数=:" + dayQu);
	} else if (monthDay == '02') {
		if ((yearDay % 4 == 0 && yearDay % 100 != 0) || yearDay % 400 == 0) {
			dayQu = 29;
			console.log("选中的是" + monthDay + "月的天数=:" + dayQu);
		} else {
			dayQu = 28;
			console.log("选中的是" + monthDay + "月的天数=:" + dayQu);
		}
	} else {
		dayQu = 30;
		console.log("选中的是" + monthDay + "月的天数=:" + dayQu);
	}
}

/*
 * 获取今天、今月、今年之前两日、月、年
 */
var legendtD = [],legendtM = [],legendtY = [];
//前天的时间
var day3 = new Date();
day3.setTime(day3.getTime() - 48 * 60 * 60 * 1000);
var s3 = day3.getFullYear() + "-" + (day3.getMonth() + 1) + "-" + day3.getDate();
console.log("前天时间=：" + s3);

//昨天的时间
var day2 = new Date();
day2.setTime(day2.getTime() - 24 * 60 * 60 * 1000);
var s2 = day2.getFullYear() + "-" + (day2.getMonth() + 1) + "-" + day2.getDate();
console.log("昨天事件=：" + s2);

//今天的时间
var day1 = new Date();
day1.setTime(day1.getTime());
var s1 = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate();
console.log("今天事件=：" + s1);
legendtD.push(s3,s2,s1,"预测趋势");
localStorage.setItem("legendtD",JSON.stringify(legendtD)); //存储日期legend
console.log("日期=="+JSON.stringify(legendtD));
/*获取这个月*/
//alert("获取这个月="+getTthisMonth(s1));
$(function(){
	$(".date1").val(s1);
	$(".date2").val(getTthisMonth(s1));
	$(".date3").val(getThisY(s3));
	$(".date4").val(getLastY(s3));
	$(".date5").val(getThisY(s3));
	
	$(".dateBox li:not(:first)").css("width", "75px")
	$(".dateBox li:not(:first) input:last-child").css("width", "55px")
	laydate.render({
		elem : ".date1",
		type : "date",
		value : s1,
	})
	laydate.render({
		elem : ".date2",
		type : "month",
		value : getTthisMonth(s1),
	})
	laydate.render({
		elem : ".date3",
		type : "year",
		value : getThisY(s3),
	})
	

	laydate.render({
		elem : ".date4", // 指定元素
		type : "year",
		value : getLastY(s3),
		theme : 'grid', // 定义主题风格

		change : function(value, date) { // 监听日期被切换
			lay('#testView').html(value);
		}
	})
	laydate.render({
		elem : ".date5", // 指定元素
		type : "year",
		value : getThisY(s3),
		theme : 'grid', // 定义主题风格

		change : function(value, date) { // 监听日期被切换
			lay('#testView').html(value);
		}
	});
	
})
function getTthisMonth(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var month = arr[1]; //获取当前日期的月份
	var day = arr[2]; //获取当前日期的日
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中月的天数
	var year2 = year;
	var month2 = parseInt(month);
	if(month2 == 0) {
		year2 = parseInt(year2) - 1;
		month2 = 12;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if(day2 > days2) {
		day2 = days2;
	}
	if(month2 < 10) {
		month2 = '0' + month2;
	}
	var t2 = year2 + '-' + month2;
	return t2;
}
/*获取上个月*/
console.log("获取上个月="+getPreMonth(s3))
function getPreMonth(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var month = arr[1]; //获取当前日期的月份
	var day = arr[2]; //获取当前日期的日
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中月的天数
	var year2 = year;
	var month2 = parseInt(month) - 1;
	if(month2 == 0) {
		year2 = parseInt(year2) - 1;
		month2 = 12;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if(day2 > days2) {
		day2 = days2;
	}
	if(month2 < 10) {
		month2 = '0' + month2;
	}
	var t2 = year2 + '-' + month2;
	return t2;
}

/*获取上个月*/
console.log("获取前个月="+getQianMonth(s3))
function getQianMonth(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var month = arr[1]; //获取当前日期的月份
	var day = arr[2]; //获取当前日期的日
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中月的天数
	var year2 = year;
	var month2 = parseInt(month) - 2;
	if(month2 == 0) {
		year2 = parseInt(year2) - 2;
		month2 = 12;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if(day2 > days2) {
		day2 = days2;
	}
	if(month2 < 10) {
		month2 = '0' + month2;
	}
	//var t2 = year2 + '-' + month2 + '-' + day2;
	var t2 = year2 + '-' + month2;
	return t2;
}
legendtM.push(getQianMonth(s3),getPreMonth(s3),getTthisMonth(s3),"预测趋势");
localStorage.setItem("legendtM",JSON.stringify(legendtM)); //存储月日期legend
console.log("月份=="+JSON.stringify(legendtM));

//获取今年
console.log("今年是="+getThisY(s3))
function getThisY(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	return year;
}
//获取去年时间
console.log("去年是="+getLastY(s3))
function getLastY(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var year2 = parseInt(year) - 1;
	
	var y2 = year2;
	return y2;
}
//获取前年时间
console.log("前年是="+getQianY(s3))
function getQianY(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var year2 = parseInt(year) - 2;
	
	var y2 = year2;
	return y2;
}
//下一年
console.log("前年是="+getNextY(s3))
function getNextY(datestr) {
	var arr = datestr.split('-');
	var year = arr[0]; //获取当前日期的年份
	var year2 = parseInt(year) + 1;
	
	var y2 = year2;
	return y2;
}


legendtY.push(getQianY(s3),getLastY(s3),getThisY(s3),"预测趋势");
localStorage.setItem("legendtY",JSON.stringify(legendtY)); //存储年legend
console.log("年份=="+JSON.stringify(legendtY));